

   public  class Solution {
    public static int getLength(String s){
        int n = s.length();
        int ret = 0;
        for(int i = 0;i<n;i++) {
            int left = i - 1;
            int right = i + 1;

                while (left >= 0 && right < n && s.charAt(left) == s.charAt(right)) {
                    left--;
                    right++;
                }
                ret = Math.max(ret, right - left - 1);

                left = i;
                right = i + 1;
                while (left >= 0 && right < n && s.charAt(left) == s.charAt(right)) {
                    left--;
                    right++;
                }
                ret = Math.max(ret, right - left - 1);
            }

        return ret;
    }
       public static String longestPalindrome(String s) {
           int ret = 0;   //代表最长回文子串
           int min = Integer.MAX_VALUE;
           int max = 0;
           int length = 0;
           for(int i =0;i<s.length();i++){
               //处理偶数的情况

               if(s.length()%2==0){
                   int left = i;  int right = i+1;
                   while(left>=0&&right<s.length()&&s.charAt(left)==s.charAt(right)){
                       left--;
                       right++;
                   }

                   if((right-left-1)==s.length()){
                       return s;
                   }
                   ret = Math.max(ret,right-left-1);
                   if(right-left-1==0){

                       continue;
                   }
                   if(length<right-left-1){
                       if(i!=0){
                           min = left+1;
                           max = right-1;
                           length = right-left-1;
                       }else{
                           length=1;
                       }
                   }
               }else{
                   int left = i-1;  int right = i+1;
                   while(left>=0&&right<s.length()&&s.charAt(left)==s.charAt(right)){
                       left--;
                       right++;
                   }
                   if((right-left-1)==s.length()){
                       return s;
                   }
                   ret = Math.max(ret,right-left-1);
                   if(right-left-1==0){

                       continue;
                   }
                   if(length<right-left-1){
                       if(i!=0){
                           min = left+1;
                           max = right-1;
                           length = right-left-1;
                       }else{
                           length=1;
                       }
                   }
               }

           }
           if(min==Integer.MAX_VALUE){
               return s.substring(0,1);
           }
           if(length==1){
               return s.substring(0,1);
           }
           return s.substring(min,max+1);
       }
       public static void main(String[] args) {
           String str = "abba";
          int a =getLength(str);
           System.out.println(a);
           System.out.println("adadad");
       }
    }

